<?php
include_once "lib/config.php";
include_once "header.php";


if(isset($_POST['post_id']) && $_POST['post_id']>0)
{
	$conditionarr=array(":id"=>$_POST['post_id']);
    $postinfo=DB::fetch_array(DB::query("select af_post_comments.*,Full_Name from af_post_comments,af_users where af_users.User_ID=af_post_comments.user_id and post_id=:id order by comment_date desc",$conditionarr));
    
   
}

?>
  		<div class="container_12" id="main_div">
           <form action="" method="post" onsubmit="return validateaddeditpost();" enctype="multipart/form-data">
			<br>
			<div class="grid_12" >
		    	<?php
            	if(isset($msg_success) && $msg_success!="")
            	{
            	?>
                <div>
                    <span class="notification n-success"><?php echo $msg_success; ?></span>
                </div>
                <?php
                }
                if(isset($msg_error) && $msg_error!="")
                {
                ?>
                <span class="notification n-error"><?php echo $msg_error; ?></span>
                <?php
				}
                ?>
		        <div class="module" >
		        		
		             <h2><span onclick="toggle_div('basic_body','toogleimg');" ><img src="images/desc.gif" height="5px" id="toogleimg">&nbsp;&nbsp;Post Comments</span></h2>
		             <?php
                     
                      for($i=0;$i<count($postinfo);$i++)
                      {
                        
                        if(isset($postinfo[$i]))
                        {
                            $data=$postinfo[$i];
                        }
                        else
                        {
                            $data=array();
                        }
    
                      
                     ?>   
		             <div class="module-body" id="basic_body">
		                
		                  	<p>
		                        <label>User Name</label>
		                        <div><?php if(isset($data['Full_Name']) && $data['Full_Name']!=Null)echo $data['Full_Name']; ?></div>
		                        
		                    </p>
		                    <p>
		                        <label>Comment</label>
		                        <?php if(isset($data['comment']) && $data['comment']!=Null)echo $data['comment']; ?>
		                    </p>
                            
                            <p>
		                        <label>Comment Date</label>
		                        <?php if(isset($data['comment_date']) && $data['comment_date']!=Null && $data['comment_date']>0)
                                {
                                    echo date("d/m/Y",$data['comment_date']);
                                }
                                ?>
		                    </p>
                            
                            
		             </div> <!-- End .module-body -->
		          <?php
                  }
                  ?>
		        </div>  <!-- End .module -->
				
		    </div>
		    
		    <div class="grid_12">
		    <fieldset>
		    	&nbsp;
		    	<input type="hidden" id="post_id" name="post_id" value="<?php if(isset($_POST['post_id'])){ echo $_POST['post_id']; } ?>">
		        <!--<input class="submit-green" type="submit" name="save" value="Submit" />--> 
		        <input class="submit-gray" type="button" value="Back" onclick="window.location='verifiedposts.php'" />
		    </fieldset>
		    </div>
		    <div style="clear:both;"></div>
		 </form>    
        </div> <!-- End .container_12 -->
		
<?php include_once("footer.php"); ?>           
<?php
if(isset($msg_success) && $msg_success!="")
{
	$notymessage=$msg_success;
	$msgtype="success";
}
else if(isset($msg_error) && $msg_error!="")
{
	$msgtype="error";
	$notymessage=$msg_error;
}
else
{
	$msgtype="";
}
if($msgtype!="")
{
?>        
<script language="javascript">
	$(document).ready(function(){
		
		var options = $.parseJSON('{"text":"<?php echo $notymessage; ?>","layout":"top","type":"<?php echo $msgtype; ?>"}');
		noty(options);
		
	});
</script>  
<?php
}
?>
<script>

function validateaddeditpost()
{
	
	if(trim(document.getElementById("name").value)=="")
	{
		alertify.alert("Post title field is required!");
		document.getElementById("name").focus();
		return false;
	}
	else if(trim(document.getElementById("type").value)=="")
	{
		alertify.alert("Post Type field is required!");
		document.getElementById("type").focus();
		return false;
	}
    else if(trim(document.getElementById("link").value)=="")
	{
		alertify.alert("Post URL field is required!");
		document.getElementById("link").focus();
		return false;
	}
    else if(trim(document.getElementById("post_photo").value)=="" && trim(document.getElementById('image_url').value)=="")
	{
		alertify.alert("Post image field is required!");
		document.getElementById("post_photo").focus();
		return false;
	}
    else if(trim(document.getElementById("smalldescription").value)=="")
	{
		alertify.alert("Post small description of maximum 50 characters is required!");
		document.getElementById("smalldescription").focus();
		return false;
	}
}
</script>       